<template>
	<el-drawer title="我的文件列表" v-model="visible" size="60%" destroy-on-close @closed="$emit('closed')">
		<el-container v-loading="loading">
			<el-header style="height: auto;">
				<sc-select-filter :data="filterData" :label-width="80" @on-change="filterChange"></sc-select-filter>
			</el-header>
			<el-header>
				<div class="left-panel">
				</div>
				<div class="right-panel">
					<div class="right-panel-search">
						<el-input v-model="search.keyword" placeholder="文件名称"></el-input>
						<el-button type="primary" icon="el-icon-search" @click="upsearch"></el-button>
					</div>
				</div>
			</el-header>
			<el-main>
				<scTable ref="table" :apiObj="apiObj" :params="{itemId:this.form.itemId}" row-key="recordId" stripe remoteSort remoteFilter>
					<el-table-column label="#" type="index" width="50"></el-table-column>
					<el-table-column label="文件名称" prop="fileName" width="200" :show-overflow-tooltip="true"></el-table-column>
					<el-table-column label="文档分类" prop="titleName" width="100" :show-overflow-tooltip="true"></el-table-column>
					<el-table-column label="关联文件" prop="" width="250" :show-overflow-tooltip="true">
						<template #default="scope">
							<attach-menu :attachIds="scope.row.attachId" :roleFlag="scope.row.attachRole" :preview="true" :uid="scope.row.recordId" @success="setFileMapReadStatus"></attach-menu>
						</template>
					</el-table-column>
					<el-table-column label="文档格式" prop="extName" width="80"></el-table-column>
					<el-table-column label="当前版本" prop="version" width="100"></el-table-column>
					<el-table-column label="查阅次数" prop="clickCount" width="80">
						<template #default="scope">
							{{ scope.row.clickCount }}/次
						</template>
					</el-table-column>
					<el-table-column label="查阅状态" prop="readStatus" width="80">
						<template #default="scope">
							<el-tag type="warning" v-if="scope.row.readStatus==0">未阅</el-tag>
							<el-tag type="success" v-else-if="scope.row.readStatus>0">已阅</el-tag>
							<el-tag type="info" v-else>未知</el-tag>
						</template>
					</el-table-column>
					<el-table-column label="当前状态" prop="fileStatus" width="80">
						<template #default="scope">
							<el-tag type="success" v-if="scope.row.fileStatus=='0'">生效中</el-tag>
							<el-tag type="warning" v-else-if="scope.row.fileStatus=='2'">已作废</el-tag>
							<el-tag type="info" v-else>未知</el-tag>
						</template>
					</el-table-column>
					<el-table-column label="创建人" prop="createUserName" width="100"></el-table-column>
					<el-table-column label="备注" prop="remark" width="150" :show-overflow-tooltip="true"></el-table-column>
				</scTable>
			</el-main>
		</el-container>
	</el-drawer>
</template>

<script>
import scSelectFilter from '@/components/scSelectFilter'
import AttachMenu from '@/views/module/attachMenu'

export default {
	emits: ['success', 'closed'],
	components: {
		scSelectFilter,
		AttachMenu,
	},
	data() {
		return {
			loading: false,
			selection: [],
			filterData: [
				{
					title: "日期范围",
					key: "date",
					multiple: false,
					options: [
						{
							label: "全部",
							value: ""
						},
						{
							label: "今日",
							value: "1"
						},
						{
							label: "昨日",
							value: "2"
						},
						{
							label: "一周内",
							value: "3"
						},
						{
							label: "一月内",
							value: "4"
						},
						{
							label: "一月前",
							value: "5"
						}
					]
				},
				{
					title: "查阅状态",
					key: "readStatus",
					multiple: false,
					options: [{
						value: '',
						label: '全部'
					}, {
						value: '1',
						label: '未阅'
					}, {
						value: '2',
						label: '已阅'
					}],
				}
			],
			form: {
				itemId: "",
			},
			apiObj: this.$API.file.fileMap.searchMyFileMapFileList,
			visible: false,
			isSaveing: false,
			search: {
				readStatus: '',
				date: '',
				keyword: '',
			}
		}
	},
	mounted() {

	},
	methods: {
		filterChange(data) {
			this.search.date = data.date;
			this.search.readStatus = data.readStatus;
			this.$refs.table.upData(this.search)
		},
		//搜索
		async upsearch() {
			this.$refs.table.upData(this.search)
		},
		async setFileMapReadStatus(data) {
			let res = await this.$API.file.fileMap.setFileMapReadStatus.post({recordId: data});
			if (res.code == 200) {
				this.$refs.table.refresh();
			} else {
				this.$alert(res.message, "提示", {type: 'error'})
			}
		},
		//显示
		open() {
			this.visible = true;
			return this;
		},
		//表单注入数据
		setData(data) {
			this.form.itemId = data.itemId
		},
	}
}
</script>

<style>
</style>
